home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: strings
- Date: Tue, 30 Jan 96 14:03:00 GMT
- Organization: none
- Message-ID: <823010580snz@genesis.demon.co.uk>
- References: <4eg9qj$1ut4@sp115.ocs.lsu.edu> <TANMOY.96Jan28104305@qcd.lanl.gov> <4ei9q3$fh1@nervous.pdb.sni.de>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4ei9q3$fh1@nervous.pdb.sni.de>
- mollers.pad@sni.de "Josef Moellers" writes:
-
- >In <TANMOY.96Jan28104305@qcd.lanl.gov> tanmoy@qcd.lanl.gov (Tanmoy
- > Bhattacharya) writes:
- >
- >>In article <4eg9qj$1ut4@sp115.ocs.lsu.edu> eenaya@unix1.sncc.lsu.edu
- >>(Pradeep Nayar) writes:
- >><snip>
- >> I saw this piece of code in a book somewhere.
- >
- >>Throw away the book: immediately.
- >
- >> char *str ;
- >
- >> str = "hello world"[10] ;
- >
- >> what does the second line do?
- >
- >>Nothing meaningful. In fact, the compiler must tell you that this is
- >>incorrect: otherwise put your compiler exactly in the same place where
- >>your book deserves to go :-)
- >
- >You _could_ be a little more precise:
- >Assuming this is C (of which I know something) and not C++ (of which I
- >know next to nothing), the only problem I see with the two lines quoted
- >above is the asterisk in the definition of "str". If you leave out the
- >asterisk, it's the declaration of a character and the assignment of the
- >letter 'd' to the character.
-
- The the variable was called 'ch' I'd agree that was probably the intention.
- However it is called 'str' so it is more likely it is the following which
- looks even stranger!
-
- char *str ;
-
- str = &"hello world"[10] ;
-
- or
-
- str = "hello world"+10 ;
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-